<?php
namespace classlib\captcha;
require 'simple/captcha_builder.cls.php';
use \classlib\captcha\simple\captcha_builder;
class simple {
	static $SSKEy = 'vcode';
	/**
	 * 展示验证码资料信息
	 * @param number $width
	 * @param number $height
	 * @param number $char
	 */
	public static function draw($ignore=false, $width=72, $height=32, $char=4) {
		$ogg = captcha_builder::create($char)
			->setIgnoreAllEffects($ignore)->build($width, $height);
		(session_id() == '') && session_start();
		$_SESSION[self::$SSKEy] = $ogg->getPhrase();
		$ogg->output();
	}
	
	/**
	 * 验证验证码信息
	 * @param string $code
	 * @return bool
	 */
	public static function verify($code) {
		(session_id() == '') && session_start();
		$res = false;
		if (isset($_SESSION[self::$SSKEy])) {
			$res = (strcasecmp($_SESSION[self::$SSKEy], $code) == 0)? true:false;
			unset($_SESSION[self::$SSKEy]);
		}
		return $res;
	}
}